package com.example.maple.ccsclient.presenter;

import android.content.Context;

import com.example.maple.ccsclient.interfaces.IReportView;
import com.example.maple.ccsclient.model.AllDataInfoUtils;
import com.example.maple.ccsclient.model.DataModel;
import com.example.maple.ccsclient.model.ISendData;

/**
 * Created by maple on 2016/6/27.
 */
public class ReportPresenter {

	private final Context mContext;
	IReportView mIReportView = null;
	AllDataInfoUtils mAllDataInfoUtils = null;

	public ReportPresenter(IReportView iReportView, Context context) {
		mContext = context;
		mIReportView = iReportView;
		mAllDataInfoUtils = new AllDataInfoUtils(mContext);
	}

	//刷新
	public void refresh(String report) {
		//显示加载
		mIReportView.showLoad();

		//获取网络数据
		mAllDataInfoUtils.getReportInfo(report, new ISendData() {
			@Override
			public void sendData(Object o) {
				DataModel<String> dataModel = (DataModel<String>) o;
				mIReportView.hiddenLoad();
				if (dataModel.getStatus() == 1) {
					mIReportView.showResult(dataModel.getData());
				} else {
					mIReportView.showDialog(dataModel.getInfo());
				}
			}
		});
	}
}
